package com.jincp.filepicker.adapter;

import com.jincp.common.brvah.BaseQuickAdapter;
import com.jincp.common.brvah.BaseViewHolder;
import com.jincp.common.utils.StringUtil;
import com.jincp.filepicker.Constant;
import com.jincp.filepicker.R;
import com.jincp.filepicker.ui.audio.AudioPickerManager;
import com.jincp.filepicker.bean.Directory;
import com.jincp.filepicker.ui.image.ImagePickerManager;

import java.util.List;

/**
 * @ProjectName: filepicker.
 * @ClassName: DirectoryAdapter.
 * @Description: .
 * @Author: jincp.
 * @CreateDate: 2019/3/23 10:51.
 */

public class DirectoryAdapter extends BaseQuickAdapter<Directory, BaseViewHolder> {

    private int directoryType;

    public DirectoryAdapter(List<Directory> data, int directoryType) {
        super(R.layout.item_directory, data);
        this.directoryType = directoryType;
    }

    @Override
    protected void convert(final BaseViewHolder holder, Directory item) {
        holder.setText(R.id.tv_directory_name, item.getName());
        if (directoryType == Constant.TYPE_IMAGE) {
            holder.setText(R.id.tv_file_count, StringUtil.formatString(R.string.format_image_count,
                    ImagePickerManager.getInstance().isShowCamera() ? item.getFiles().size() - 1 : item.getFiles().size()));
        } else if (directoryType == Constant.TYPE_AUDIO) {
            holder.setText(R.id.tv_file_count, StringUtil.formatString(R.string.format_audio_count, item.getFiles().size()));
        } else if (directoryType == Constant.TYPE_VIDEO) {
            holder.setText(R.id.tv_file_count, StringUtil.formatString(R.string.format_video_count, item.getFiles().size()));
        } else if (directoryType == Constant.TYPE_FILE) {
            holder.setText(R.id.tv_file_count, StringUtil.formatString(R.string.format_file_count, item.getFiles().size()));
        }
        holder.setVisible(R.id.iv_directory_check, item.isSelected());
    }

    public void setSingleChoice(int position) {
        for (int i = 0; i < getData().size(); i++) {
            if (getItem(i) == null) continue;
            getItem(i).setSelected(i == position);
        }
        notifyDataSetChanged();
    }
}
